package com.dingding.api.controller.base;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

/**
 * 
 * @ClassName: PayBaseController 
 * @Description: 第三方支付回调抽象类
 * @author CHEHAUNBO 
 * @date 2016年7月6日 下午3:32:33
 * 
 */
public abstract class PayBaseController extends BaseController {

	private static Logger log = Logger.getLogger(PayBaseController.class);

	/**
	 * 
	 * 支付宝回调方法
	 * 
	 * @Title: alipayNotify 
	 * @author CHEHAUNBO
	 * @since V2.3.0
	 * 
	 */
	public abstract void alipayNotify(HttpServletRequest request, HttpServletResponse response);

	/**
	 * 微信支付回调方法
	 * @Title: weChatNotify 
	 * @author CHEHAUNBO
	 * 
	 */
	public abstract void weChatNotify(HttpServletRequest request, HttpServletResponse response);

	/**
	 * 
	 * 支付宝回调成功后需要打印success
	 * 支付宝收到success后回调才算成功
	 * 
	 * @Title: returnSuccess 
	 * @param response  
	 * @author CHEHAUNBO
	 * 
	 */
	public void returnSuccess(HttpServletResponse response) {
		try {
			response.getWriter().print("success");
			response.getWriter().flush();
			response.getWriter().close();
		} catch (IOException e) {
			log.error("支付宝回调打印SUCCESS失败！", e);
		}
	}

	/**
	 * 
	 * 回调成功响应给微信的XML
	 * 
	 * @Title: responseOkToWechat 
	 * @author CHEHAUNBO
	 * 
	 */
	protected void responseOkToWechat(HttpServletResponse response) {
		String str = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
		super.renderText(str,response);
	}

	/**
	 * 
	 * 回调失败响应给微信的XML
	 * 
	 * @Title: responseOkToWechat 
	 * @author CHEHAUNBO
	 * 
	 */
	protected void responseFailToWechat(HttpServletResponse response) {
		String str = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[FAIL]]></return_msg></xml>";
		super.renderText(str,response);
	}

}
